//index.js
//获取应用实例

const mockData = {

    info:{
        id: '0',
        status: 0,
        type_name: '开工',
        size: 123,
        address: '不知道',
        starttime: 232323,
        endtime: 29382,
        username: '好的',
        phone: '1212',
        avatar: null,
        createtime: 10000,
        supplier_name: '好啊',
        supplier_phone: '121234',
        supplier_avatar: null,
        total_price: 100
    },
    
}

const app = getApp();
// var template = require('../header/header.js');

Page({
    data: {
        orderId: 0,
        info: {}
    },
    onLoad: function (options) {
        if(typeof options.id != 'undefined') {
            this.setData({
                orderId: options.id
            })
            this.getInfo();
        }
    },
    onHide: function () {

    },

    getInfo: function() {
        var _this = this;
        var object = {
            url: app.api.url.order.orderDetail,
            data: {order_id: this.data.orderId},
            success: function(res) {
                if(res.status == 1) {

                    res.data.starttime = app.util.dateTime(res.data.starttime, 'Y-m-d');
                    res.data.endtime = app.util.dateTime(res.data.endtime, 'Y-m-d');

                    res.data.stageList = res.data.stageList.map(item =>{

                        item.starttime = app.util.dateTime(item.starttime, 'Y-m-d');
                        item.endtime = app.util.dateTime(item.endtime, 'Y-m-d');

                        return item;
                        
                    })
                    
                    _this.setData({
                        info: res.data
                    })
                } else {
                    app.showToast(res.info);
                }
            }
        }
        app.request(object);
    }
});
